{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5667c040",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'> <class 'float'> <class 'bool'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a, b, c, d = 12, 3.14, True, \"你好\"\n",
    "print(type(a), type(b), type(c), type(d))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c20b8b9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "print(isinstance(a, int))\n",
    "print(isinstance(a, float))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8ee181e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.3333333333333335\n",
      "3\n",
      "1\n",
      "1000\n",
      "13.14\n"
     ]
    }
   ],
   "source": [
    "a = 10/3 #浮点除法\n",
    "b = 10//3 #整点除法\n",
    "c = 10%3 #取余\n",
    "d = 10**3 #幂操作\n",
    "e = 10 + 3.14 #在混合计算时，Python会把整型转换成为浮点数\n",
    "print(a)\n",
    "print(b)\n",
    "print(c)\n",
    "print(d)\n",
    "print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "075ea006",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pythonpython\n",
      "\n",
      "ho\n"
     ]
    }
   ],
   "source": [
    "str_test = 'python'\n",
    "print(str_test * 2)\n",
    "print(str_test[-1:-3])#输出为空\n",
    "print(str_test[-3:-1])#输出ho，索引的值只能从小到大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "12418244",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "love\n",
      "peace\n",
      "love\\npeace\n",
      "tom say:\"hello\"\n",
      "tom say:\"hello\"\n"
     ]
    }
   ],
   "source": [
    "str_a = 'love\\npeace'\n",
    "print(str_a)\n",
    "str_a = r'love\\npeace'#Python 使用反斜杠 \\ 转义特殊字符，如果你不想让反斜杠发生转义，可以在字符串前面添加一个 r，表示原始字符串：\n",
    "print(str_a)\n",
    "greetings = 'tom say:\\\"hello\\\"'\n",
    "greetings1 = r'tom say:\"hello\"'\n",
    "print(greetings)\n",
    "print(greetings1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "80c63545",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "a = 123\n",
    "b = 123.0\n",
    "print(a==b)\n",
    "print(a!=b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7b4d0684",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "even\n"
     ]
    }
   ],
   "source": [
    "num1 = 66\n",
    "if num1%2==0:\n",
    "    print(\"even\")\n",
    "else:\n",
    "    print(\"odd\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "93d92938",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 到50 的和是: 1275\n"
     ]
    }
   ],
   "source": [
    "# while 循环\n",
    "n = 50\n",
    "sum_n = 0\n",
    "counter = 1\n",
    "while counter <= n:\n",
    "    sum_n += counter\n",
    "    counter += 1\n",
    "print(\"1 到%d 的和是: %d\"%(n, sum_n))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "32b17ae3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "550\n"
     ]
    }
   ],
   "source": [
    "start = 10\n",
    "end = 100\n",
    "step = 10\n",
    "sum_n = 0\n",
    "for i in range(start, end+1, step):# range(start, end+1, step)\n",
    "    sum_n += i\n",
    "print(sum_n)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7ceb5c2b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "找到你了\n"
     ]
    }
   ],
   "source": [
    "for i in range(1, 10):\n",
    "    if i==5:\n",
    "        print(\"找到你了\")\n",
    "        break # 跳出当前的for循环\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "301d7232",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "找到你了\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(1, 10):\n",
    "    if i==5:\n",
    "        print(\"找到你了\")\n",
    "        continue # 跳出当前这一次的for循环\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b3b0719f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第1次循环开始...\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "找到你了\n",
      "第2次循环开始...\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "找到你了\n",
      "第3次循环开始...\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "找到你了\n",
      "第4次循环开始...\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "找到你了\n"
     ]
    }
   ],
   "source": [
    "flag = True\n",
    "cnt = 1\n",
    "while flag==True:\n",
    "    print(\"第%d次循环开始...\"%cnt)\n",
    "    for i in range(1, 10):\n",
    "        if i==5:\n",
    "            print(\"找到你了\")\n",
    "            break # 只会跳出里面的for循环，不会跳出外面的while循环\n",
    "        print(i)\n",
    "    cnt+=1\n",
    "    if cnt >= 5:\n",
    "        flag = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a087d79f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
